package com.lineage.data.item_etcitem;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.datatables.lock.SpawnBossReading;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Spawn;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Map;

public class ItemBoss extends ItemExecutor {
  public static ItemExecutor get() {
    return new ItemBoss();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    String[] htmldata1 = null;
    htmldata1 = new String[150];
    int i = 0;
    try {
      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Map<Integer, L1Spawn> BossSpawn = SpawnBossReading.get().get_bossSpawnTable();
      Iterator<L1Spawn> iterator = BossSpawn.values().iterator();
      while (iterator.hasNext()) {
        L1Spawn spawn = iterator.next();
        if (i > 150)
          break; 
        if (Calendar.getInstance().after(spawn.get_nextSpawnTime())) {
          htmldata1[i] = String.valueOf(String.valueOf(spawn.getName())) + "\n ->[已刷新]";
        } else {
          htmldata1[i] = String.valueOf(String.valueOf(spawn.getName())) + "\r\n" + 
            sdf.format(spawn.get_nextSpawnTime().getTime());
        } 
        i++;
      } 
      pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(pc.getId(), "serverboss", htmldata1));
    } catch (Exception e) {
      e.printStackTrace();
    } 
  }
}
